<template>
	<view class="contina bBtn_p_b140">
		<view class="w" style="height: calc(100% - 20rpx);">
			<scroll-view scroll-y class="scrollView" v-if="list.length > 0" @scrolltolower="getList">
				<u-checkbox-group v-model="groupVal" placement="column">
					<template v-for="(item,idx) in list">
						<view class="card">
							<view style="width: 15%;">
								<u-checkbox shape="circle" :customStyle="{ marginBottom: '8px' }" label=" " :name="idx">
								</u-checkbox>
							</view>
							<view style="width: 85%;">
								<view class="top">
									<view class="orderNo">单号：{{item.no}}</view>
									<view class="payTime">购买日期：{{item.updated_at}}</view>
								</view>
								<view class="content">
									<view class="flex_a_c par">
										<view class="label">企业名称</view>
										<view class="value">{{item.corp.name}}</view>
									</view>
									<view class="flex_a_c par">
										<view class="label">服务内容</view>
										<view class="value">{{item.product_title}}</view>
									</view>
									<view class="flex_a_c par">
										<view class="label">有效期</view>
										<view class="value">{{item.start_at}}至{{item.end_at}}</view>
									</view>
								</view>
								<view class="price">
									<view class="t">{{item.amount}}</view>
									<view class="i">¥</view>
								</view>
							</view>
						</view>
					</template>
				</u-checkbox-group>
			</scroll-view>
			<view class="no" v-else>
				<image src="../../static/image/none.png"></image>
				<view class="em">暂无数据</view>
			</view>
		</view>
		<flooterCom>
			<template #btn>
				<view class="flex_a_c" style="justify-content: space-around;">
					<view class="info btns">
						<view>
							<u-checkbox-group v-model="groupAll" placement="column">
								<u-checkbox shape="circle" label="全选" name="All" @change="allChkeck()">
								</u-checkbox>
							</u-checkbox-group>
						</view>
						<view class="orderInfo">
							<text style="color: #DF9E5C;">{{groupVal.length}}</text>条订单记录 共<text
								style="color: #DF9E5C;">{{amount}}</text>元
						</view>
					</view>
					<view class="save btns" @click="next">
						下一步
					</view>
				</view>
			</template>
		</flooterCom>
	</view>
</template>

<script>
	import searchCom from "@/compoment/searchCom.vue";
	import flooterCom from "@/compoment/flooterCom.vue"
	export default {
		data() {
			return {
				list: [],
				page: 1,
				groupVal: [],
				groupAll: [],
				isAll: false,
				amount: '0.00',
				ids: ''
			}
		},
		watch: {
			groupVal(val) {
				if (val.length === this.list.length) {
					this.isAll = true;
					this.groupAll = ['All']
				} else {
					this.isAll = false;
					this.groupAll = []
				}
				let a = 0;
				let ids = [];
				for (let k in this.groupVal) {
					a += parseFloat(this.list[this.groupVal[k]].amount)
					ids.push(this.list[this.groupVal[k]].id)

				}
				this.amount = a.toFixed(2)
				this.ids = ids.join(',')
			}
		},
		components: {
			searchCom,
			flooterCom
		},
		onShow() {
			this.getList()
		},
		onHide() {
			this.page = 1
			this.list = []
		},
		methods: {
			toAdd() {
				uni.navigateTo({
					url: "/pagesB/entetiyPlus/entetiyPlus"
				})
			},
			async getList() {
				let res = await this.$api.corpPayApi.list({
					page: this.page,
				})
				if (res.list.length) {
					this.list = this.list.concat(res.list)
					this.page++
				}
			},
			allChkeck() {
				if (!this.isAll) {
					this.list.map((item, idx) => {
						this.groupVal.push(idx)
					})
					this.isAll = true;
				} else {
					this.groupVal = []
					this.isAll = false;
				}
			},
			next() {
				if(this.groupVal.length<1){
					uni.showToast({
						icon:'none',
						title:'未选择订单'
					})
					return
				}
				uni.navigateTo({
					url: "/pagesB/invoiceinfo/invoiceinfo?ids=" + this.ids + '&amount='+this.amount
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.contina {
		height: 100%;

		::v-deep .u-icon__icon {
			color: #ffffff !important;
		}

		.seach {
			padding: 20rpx 30rpx;
			background-color: #fff;
			box-sizing: border-box;

			.tabs {
				justify-content: space-between;
				align-items: center;
				font-size: 26rpx;
				font-weight: 400;
				color: #3D3D3D;
				margin-top: 30rpx;
			}
		}

		.scrollView {
			height: 100%;

			.card {
				padding: 30rpx;
				box-sizing: border-box;
				position: relative;
				margin-top: 20rpx;
				display: flex;
				align-items: center;

				.top {
					.orderNo {
						font-size: 28rpx;
						font-weight: 400;
						color: #000000;
					}

					.payTime {
						font-size: 28rpx;
						font-weight: 400;
						color: #888888;
						margin-top: 10rpx;
					}
				}

				.content {
					box-sizing: border-box;
					background: #F5F8FF;
					border-radius: 5px 5px 5px 5px;
					padding: 30rpx;
					margin-top: 30rpx;

					.par {
						justify-content: space-between;
						margin-bottom: 30rpx;
					}

					.par:last-child {
						margin-bottom: 0;
					}

					.label {
						font-size: 28rpx;
						font-weight: 400;
						color: #999999;
						margin-right: 20rpx;
					}

					.value {
						font-size: 24rpx;
						font-weight: 400;
						color: #000000;
					}
				}

				.price {
					display: flex;
					align-items: flex-end;
					font-size: 32rpx;
					font-weight: 400;
					color: #000000;
					flex-direction: row-reverse;
					margin-top: 30rpx;

					.i {
						font-size: 24rpx;
					}

					.t {
						margin-left: 5rpx;
					}
				}
			}
		}

		image {
			width: 412rpx;
			height: 284rpx;
			border-radius: 0px 0px 0px 0px;
		}

		.no {
			margin-top: 50rpx;
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			margin-top: 332rpx;

			.em {
				width: 128rpx;
				height: 50rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #888888;
			}
		}

		.btns {
			width: 330rpx;
			height: 90rpx;
			line-height: 90rpx;
			text-align: center;
			border-radius: 50px 50px 50px 50px;
		}

		.info {
			text-align: left;

			.orderInfo {
				font-size: 24rpx;
				font-weight: 400;
				letter-spacing: 1px;
			}
		}

		.save {
			color: #fff;
			background-color: #0074FF;
		}
	}
</style>